﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;

namespace EmailClient
{

    static internal class ResourcesLoader
    {
        //Get the resource dictionary for assembly with a given culture.
        static private ResourceDictionary _GetResourceDictionary(CultureInfo cultureInfo)
        {
            ResourceDictionary dictionary = new ResourceDictionary();
            var resourceSet = Properties.Resources.ResourceManager.GetResourceSet(cultureInfo, true, true);
            foreach (DictionaryEntry item in resourceSet)
                dictionary.Add(item.Key, item.Value);

            return dictionary;
        }

        static public void LoadResources(ResourceDictionary resourceDictionary)
        {
            //Get the dictionary for the main assembly.
            ResourceDictionary defaultDictionary = _GetResourceDictionary(DEFAULT_CULTURE);

            //Merge this dictionary with other dictionaries applications
            resourceDictionary.MergedDictionaries.Add(defaultDictionary);

            // If the current culture is different from the default culture -
            //ship resources from satellite assemblies current culture
            if (Thread.CurrentThread.CurrentUICulture.CompareInfo !=
                DEFAULT_CULTURE.CompareInfo)
            {
                ResourceDictionary localizedDictionary =
                    _GetResourceDictionary(Thread.CurrentThread.CurrentUICulture);
                resourceDictionary.MergedDictionaries.Add(localizedDictionary);
            }
        }

        private static CultureInfo DEFAULT_CULTURE = CultureInfo.GetCultureInfo("en-US");
    }

}
